﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using RestSharp;
using Ymatou.ServiceCenter;
using YmatouSeller.Common.API;
using YmatouSeller.NoticeAPI.Model.Response;

namespace YmatouSeller.NoticeAPI.Model.Request
{
    [Resource("sellernotice.iapi.ymatou.com", "api/NoticeManage/UploadFile", Method.POST, ParameterBuildType.Json)]
    public class UploadFileRequest : BaseRequestModel<UploadFileResponse>
    {
        public override string ApiName
        {
            get { return "api/NoticeManage/UploadFile"; }
        }

        public override bool HttpGet
        {
            get { return false; }
        }
        /// <summary>
        /// 文件名必须带后缀(xxx.jpg)
        /// </summary>
        public string FileName { get; set; }
        public string UploadData { get; set; }
        /// <summary>
        /// 文件类型(1图片，2文件)
        /// </summary>
        public int UploadType { get; set; }

        public override void Validate()
        {
            const string errCode = "-1";
            if (UploadType != 1 && UploadType != 2)
            {
                throw new Ymatou.API.Common.BussniessException(errCode, "文件类型参数不正确");
            }
            if (string.IsNullOrEmpty(FileName))
            {
                throw new Ymatou.API.Common.BussniessException(errCode, "文件名不能为空");
            }
            if (string.IsNullOrEmpty(UploadData))
            {
                throw new Ymatou.API.Common.BussniessException(errCode, "上传文件不能为空");
            }

            //FileInfo file = new FileInfo(FileName);
            ////获取文件类型
            //string fileContentType = file.Extension.ToUpper();
            //List<string> canUploadFileType = new List<string>();
            //if (UploadType == 1)
            //{
            //    //获取配置可上传的图片格式
            //    canUploadFileType = new List<string> { ".JPG", ".PNG" };
            //}
            //else
            //{
            //    //获取配置可上传的文件格式
            //    canUploadFileType = new List<string> { ".DOC", ".DOCX" };
            //}
            //if (!canUploadFileType.Contains(fileContentType))
            //{
            //    throw new Ymatou.API.Common.BussniessException(errCode, "上传文件类型不正确");
            //}

            base.Validate();
        }
    }
}
